package com.hcrazy.manchester.app.services;

import org.joda.time.DateTime;

import com.hcrazy.manchester.app.jdbc.AttachmentDAO;
import com.hcrazy.manchester.app.pojo.Attachment;
import com.hcrazy.manchester.app.pojo.ErrorMsg;
import com.hcrazy.manchester.app.pojo.PageModel;
import com.hcrazy.manchester.app.utils.Constant;

public class AttachmentService {

	private AttachmentDAO attachmentDAO;
	
	public AttachmentDAO getAttachmentDAO() {
		return attachmentDAO;
	}

	public void setAttachmentDAO(AttachmentDAO attachmentDAO) {
		this.attachmentDAO = attachmentDAO;
	}

	public ErrorMsg addAttachment(Attachment attachment) throws Exception{
		ErrorMsg msg = new ErrorMsg();
		msg.setCode(Constant.SUCCESS);
		DateTime dt = new DateTime();
		attachment.setAttachmentTime(dt.toString("yyyy-MM-dd hh:mm:ss"));
		attachmentDAO.addAttachment(attachment);
		return msg;
	}
	
	public PageModel getAttachments(PageModel model,String fileName,String username,String startTime,String endTime,long forumId) throws Exception{
		return attachmentDAO.getPagedInfos(model, fileName, username, startTime, endTime, forumId);
	}
	
	public Attachment getInfoById(int attachmentId) throws Exception{
		return attachmentDAO.getById(attachmentId);
	}
	
	public void delAttachment(long attachmentId) throws Exception{
		attachmentDAO.delAttachment(attachmentId);
	}
	
	public PageModel getAttachments(PageModel model,long forumId) throws Exception{
		return attachmentDAO.getAttachments(model, forumId);
	}
}
